#
# NESDroid
# Copyright 2011 Stephen Damm (Halsafar) 
# All rights reserved.
# shinhalsafar@gmail.com
#

LOCAL_PATH := $(call my-dir)
ORG_PATH := $(LOCAL_PATH)

# BUILD ALL EXTERNAL LIBS
include $(CLEAR_VARS)
include $(call all-makefiles-under,$(LOCAL_PATH))


# BUILD EMU LIB
include $(CLEAR_VARS)
LOCAL_PATH := $(ORG_PATH)/

LOCAL_MODULE_TAGS := user

LOCAL_ARM_MODE := arm

LOCAL_MODULE := libemu

MY_FILES 	:=	\
				$(wildcard $(LOCAL_PATH)/../fceu_src/*.cpp) \
				$(wildcard $(LOCAL_PATH)/../fceu_src/mappers/*.cpp) \
				$(wildcard $(LOCAL_PATH)/../fceu_src/mappers/*.c) \
				$(wildcard $(LOCAL_PATH)/../fceu_src/boards/*.cpp) \
				$(wildcard $(LOCAL_PATH)/../fceu_src/input/*.cpp) \
				$(wildcard $(LOCAL_PATH)/../fceu_src/utils/*.cpp) \
				$(wildcard $(LOCAL_PATH)/../fceu_src/drivers/common/*.cpp) \
				$(wildcard $(LOCAL_PATH)/../fceu_src/drivers/common/*.c) \
				
# For Lua
#MY_FILES	+=	\
				$(wildcard $(LOCAL_PATH)/../fceu_src/lua/src/*.c) \
				$(wildcard $(LOCAL_PATH)/../fceu_src/*.c)	
		
# Correct the file names		
MY_FILES := $(MY_FILES:$(LOCAL_PATH)/%=%) 

# Emulator Engine source files that we will compile.
LOCAL_SRC_FILES := \
	FceuSystem.cpp \
	EmulatorBridge.cpp \
	GraphicsDriver.cpp \
	Application.cpp \
	InputHandler.cpp \
	Quad.cpp \
	$(MY_FILES)		
	                  
# Debug
#LOCAL_CFLAGS += -g

# Compiler flags.
LOCAL_CFLAGS := -I. \
				-I./fceu_src/lua/src/ \
				-D_STLP_HAS_WCHAR_T -D_GLIBCXX_USE_WCHAR_T
	
# Optimization flags
LOCAL_CFLAGS += -O3 \
				-ffast-math \
				-fomit-frame-pointer \
				-fvisibility=hidden
				#-funroll-loops \
				#-finline-functions \
				#-mfloat-abi=softfp \
				#-mfpu=neon
				#--param inline-unit-growth=1000 \
				#--param large-function-growth=5000 \
				#--param max-inline-insns-single=2450
				# -fvisibility=hidden
				
#LOCAL_CFLAGS += -UDEBUG \
				-march=armv5te \
				-mtune=xscale \
				-msoft-float \
				-mthumb-interwork \
				-fpic \
				-ffunction-sections \
				-funwind-tables \
				-fstack-protector \
				-fmessage-length=0 \
				-Bdynamic 
			
# Compiler Warning flags
#LOCAL_CFLAGS += -Winline
LOCAL_CFLAGS += -Wno-write-strings

# Custom Emulator Flags
LOCAL_CFLAGS += -DHALDROID -DANDROID

# FCEU Flags
LOCAL_CFLAGS += -DPSS_STYLE=1 -DHAVE_ASPRINTF -DC80x86 -DLSB_FIRST -DFRAMESKIP

# FCEU Enable Lua 
#LOCAL_CFLAGS += -D_S9XLUA_H -D_USE_FCEU_LUA_ENGINE

# Copy C Flags to CXX flags
LOCAL_CPPFLAGS := $(LOCAL_CFLAGS)
LOCAL_CXXFLAGS := $(LOCAL_CFLAGS)
     

# Native libs to link to
LOCAL_LDLIBS := -lz -llog -lGLESv2

# All of the shared libraries we link against.
LOCAL_SHARED_LIBRARIES := libzip libgnupng

                   
# Static libraries.              
LOCAL_STATIC_LIBRARIES :=   

# Don't prelink this library.  For more efficient code, you may want
# to add this library to the prelink map and set this to true. However,
# it's difficult to do this for applications that are not supplied as
# part of a system image.
LOCAL_PRELINK_MODULE := false

include $(BUILD_SHARED_LIBRARY)


